package com.lff.service.impl;


import com.lff.domain.User;
import com.lff.mapper.UserMapper;
import com.lff.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String userCode, String userPassword) {
        return userMapper.findUserByUsernameAndPassword(userCode, userPassword);
    }

    @Override
    public User checkPwd(Long id, String oldPassword) {
        return userMapper.findUserByUserIdAndPassword(id, oldPassword);
    }

    @Override
    public boolean updatePassword(Long id, String newpassword) {
        int update = userMapper.changePwd(id, newpassword);
        if (update > 0) {
            //修改成功
            return true;
        }
        return false;
    }

    @Override
    public List<User> findAll(String queryname, Integer queryUserRole) {
        return userMapper.findAll(queryname, queryUserRole);
    }

    @Override
    public User findById(Integer uid) {
        return userMapper.findById(uid);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    @Override
    public Integer deleteById(Long id) {
        return userMapper.deleteById(id);
    }

    @Override
    public User queryUserCode(String userCode) {
        return userMapper.findUserByUserCode(userCode);
    }

    @Override
    public void addUser(User user) {
        userMapper.save(user);
    }
}
